using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CompanyDomain;
//using ShivamEMR.Web.Areas.Company.Models;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Company.Controllers
{   
    public class CompanyGroupController : Controller
    {
		private readonly ICompanyGroupRepository companygroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public CompanyGroupController() 
        {
            companygroupRepository = Registry.RepositoryFactory.GetCompanyGroupRepository();
        }

        public CompanyGroupController(ICompanyGroupRepository companygroupRepository)
        {
			this.companygroupRepository = companygroupRepository;
        }

        //
        // GET: /CompanyGroup/

        public ViewResult Index()
        {
           // return View(companygroupRepository.AllIncluding(companygroup => companygroup.Companies));
            return View(companygroupRepository.All);
        }

        //
        // GET: /CompanyGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(companygroupRepository.Find(id));
        }

        //
        // GET: /CompanyGroup/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /CompanyGroup/Create

        [HttpPost]
        public ActionResult Create(CompanyGroup companygroup)
        {
            if (ModelState.IsValid) {
                companygroupRepository.Create(companygroup);
                companygroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /CompanyGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(companygroupRepository.Find(id));
        }

        //
        // POST: /CompanyGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(CompanyGroup companygroup)
        {
            if (ModelState.IsValid) {
                companygroupRepository.Update(companygroup);
                companygroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /CompanyGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(companygroupRepository.Find(id));
        }

        //
        // POST: /CompanyGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
          //  companygroupRepository.Delete(id);
            var cg = companygroupRepository.Find(id);
            companygroupRepository.Delete(cg);
            companygroupRepository.Save();

            return RedirectToAction("Index");
        }

        public ICompanyGroupRepository Regristry { get; set; }
    }
}

